//
//  YSSearchListHeaderView.m
//  Yueshi
//
//  Created by yueshi－mac1 on 16/2/22.
//  Copyright © 2016年 悦食中国. All rights reserved.
//

#import "YSSearchListHeaderView.h"
@interface YSSearchListHeaderView()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *grayLineHeightCons;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *grayLineTopCons;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIView *containView;

@property (strong, nonatomic) UIButton *moreBtn;
@property (assign, nonatomic) BOOL hasLine;
@end

@implementation YSSearchListHeaderView

+ (instancetype)headerView{
    return [[[NSBundle mainBundle] loadNibNamed:@"YSSearchListHeaderView" owner:nil options:nil] lastObject];
}

- (void)awakeFromNib{
    NSString *more = @"更多";
    CGSize moreSize = [more sizeWithFont:SYS_FONT(13)];
    UIImage *moreImage = [UIImage imageNamed:@"btn_in"];
    
    UIButton *moreBtn = [[UIButton alloc] init];
    [moreBtn.titleLabel setFont:SYS_FONT(13)];
    [moreBtn setTitle:more forState:UIControlStateNormal];
    [moreBtn setTitleColor:publicTextColor forState:UIControlStateNormal];
    [moreBtn setImage:moreImage forState:UIControlStateNormal];
    
    CGSize moreImageSize = CGSizeMake(moreImage.size.width + 3, moreImage.size.height);
    moreSize = CGSizeMake(moreSize.width +2, moreSize.height);
    
    [moreBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -moreImageSize.width, 0, moreImageSize.width)];
    [moreBtn setImageEdgeInsets:UIEdgeInsetsMake(0, moreSize.width, 0, -moreSize.width)];
    
    moreBtn.frame = CGRectMake(SCREENW - 10 - moreSize.width - moreImageSize.width, 0, moreSize.width + moreImageSize.width, self.containView.height);
    
    [self.containView addSubview:moreBtn];
    _moreBtn = moreBtn;
    [moreBtn addTarget:self action:@selector(moreClick:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)moreClick:(UIButton *)sender{
    if (self.moreClick) {
        self.moreClick();
    }
}

-(void)setHasGrayLine:(BOOL)hasGrayLine{
    if (!hasGrayLine) {
        self.grayLineHeightCons.constant = 0;
        self.grayLineTopCons.constant = 0;
        self.height = self.height - 15;
    }
}

//- (void)layoutSubviews{
//    self.moreBtn.y = self.containView.y;
//}

-(void)setData:(NSString *)data{
    [self.titleLabel setText:data];
}

- (void)setCount:(NSUInteger *)count{
    self.moreBtn.hidden = (int)count<4;
}

@end
